<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>公司信息</title>
<%@ include file="../../common/common.jsp"%>

</head>
<script type="text/javascript">
//新增公司
function newCp_info(){
	$('#dlg').dialog('open').dialog('setTitle', '新增公司');
	$('#fm').form('clear');
}
//编辑公司信息
function editCp_info() {
	var row = $('#dg').datagrid('getSelected');
	if (row) {
		$('#dlg').dialog('open').dialog('setTitle', '编辑公司');
		$('#fm').form('load', row);
	}
}

//保存公司信息
function saveCp_info() {
	$('#fm').form('submit', {
		url : '<%=basePath %>saveCompanyAction!saveData.do',
		onSubmit : function() {
			return $(this).form('validate');
		},
		success : function(result) {
			var result = eval('(' + result + ')');
			//alert(result);
			if (result.message=='success') {
				$('#dlg').dialog('close'); // close the dialog
				$('#dg').datagrid('reload'); // reload the user data
		} else {
		$.messager.show( {
			title : '错误提示',
			msg : result.message
		});
	}
}
	});
}

function removeCp_info() {
	var row = $('#dg').datagrid('getSelected');
	if (row) {
		$.messager.confirm('Confirm',
				'请确认是否删除该公司信息?', function(r) {
					if (r) {
						$.post('<%=basePath %>saveCompanyAction!destoryData.do', {
							id : row.id
						}, function(result) {
							if (result.message=='success') {
								$('#dg').datagrid('reload'); // reload the user data
							} else {
								$.messager.show( { // show error message
										title : '错误提示',
										msg : result.message
										});
							}
						}, 'json');
					}
				});
	}
}
</script>
<body>
<body>
		<table id="dg" title="公司信息" class="easyui-datagrid"
			style="width: 1000px; height: 370px" url="<%=basePath %>jsp/GetJson.jsp?type=companyinfoList"
			toolbar="#toolbar" pagination="true" rownumbers="true"
			fitColumns="true" singleSelect="true" >
			<thead>
				<tr>
					<th field="companyCode" width="20">
						公司代码
					</th>
					<th field="companyName" width="30">
						公司名称
					</th>
				</tr>
			</thead>
		</table>
		
		
		<div id="toolbar">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
				onclick="newCp_info()">新建</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-edit"
				plain="true" onclick="editCp_info()">编辑</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-remove"
				plain="true" onclick="removeCp_info()">删除</a>
		</div>
		
		<div id="dlg" class="easyui-dialog"
			style="width: 600px; height: 180px; padding: 10px 20px" closed="true"
			buttons="#dlg-buttons">
			<div class="ftitle">
				公司信息
			</div>
			<form id="fm" method="post" >
				<table>
				
					<tr colspan="2" style="display: none">
						
						<td>
							<div class="fitem">
								<label>
									ID:
								</label>
								<input name="id" class="easyui-validatebox" >
							</div>
						</td>
						
					</tr>
					
					<tr>
						
						<td width="207px">
							<div class="fitem">
								<label>
									公司代码:
								</label>
								<input name="companyCode" class="easyui-validatebox" required="true">
							</div>
						</td>
						<td>
							<div class="fitem">
								<label>
									公司名称:
								</label>
								<input name="companyName" class="easyui-validatebox" required="true">
							</div>
						</td>

					</tr>

				</table>

			</form>
		</div>
		<div id="dlg-buttons">
			<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
				onclick="saveCp_info()">Save</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-cancel"
				onclick="javascript:$('#dlg').dialog('close')">Cancel</a>
		</div>
</body>
</html>